from ronglian_sms_sdk import SmsSDK
import json

accId = '2c94811c9787a27f01985926e8772c7a'
accToken = 'f4f7ebde6ae742faa3dd29745f0e6aae'
appId = '2c94811c9787a27f01985926ea272c81'


def send_message(phone, code):
    sdk = SmsSDK(accId, accToken, appId)
    tid = '1'
    mobile = phone
    datas = (code,)
    resp = sdk.sendMessage(tid, mobile, datas)
    # 保证返回 JSON 对象
    if isinstance(resp, str):
        try:
            return json.loads(resp)
        except Exception:
            return {"status": "error", "msg": resp}
    return resp
